package com.wncinema.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendDuanXin {
	//验证码信息
public static String sendMessage(String phoneNumber) {
	 String code=vcode();
	 DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAImzp4RMcplIk3", "rEyZYNQV4J2T6yNlg6KQTQUVlYTPvZ");
     IAcsClient client = new DefaultAcsClient(profile);
     CommonRequest request = new CommonRequest();
     request.setMethod(MethodType.POST);
     request.setDomain("dysmsapi.aliyuncs.com");
     request.setVersion("2017-05-25");
     request.setAction("SendSms");
     request.putQueryParameter("RegionId", "cn-hangzhou");
     request.putQueryParameter("PhoneNumbers", phoneNumber);
     request.putQueryParameter("SignName", "蜗牛影城");
     request.putQueryParameter("TemplateCode", "SMS_171188224");
     request.putQueryParameter("TemplateParam", "{\'code\':\'"+code+"\'}");
     try {
         CommonResponse response = client.getCommonResponse(request);
         System.out.println(response.getData());
     } catch (ServerException e) {
         e.printStackTrace();
     } catch (ClientException e) {
         e.printStackTrace();
     }
	return code;
}

/**
	 * 生成4位随机数验证码
	 * @return
	 */
	public static String vcode(){
		String vcode = "";
       for (int i = 0; i <4; i++) {
           vcode = vcode + (int)(Math.random() * 9);
       }
       return vcode;
	}	
}
